package com.xbniao.owms.utils.barcode;

import com.itextpdf.text.Document;
import com.itextpdf.text.PageSize;
import com.xbniao.owms.utils.StringLengthUtil;

public class CommodityBarCodeParamByTemplateCode {

	/********单位：磅********/
	private float _table_width = PageSize.A4.getWidth();
	private float _bar_code_font_size = 10f;
	private float _bar_code_height = 36f;
	private float _bar_code_padding_top_size = 0f;
	private float _bar_code_cell_fixed_hight = 0f;
	private float _text_padding_bottom_size = 0f;
	private float _text_padding_top_size = 0f;
	private float _padding_bottom_size = 0f;
	private float _padding_right_size = 0f;
	private float _bar_code_width = 0f;
	
	public CommodityBarCodeParamByTemplateCode(String code)
	{
		this._table_width = this.getMainTableWidth(code);
		this._bar_code_font_size = this.getBarCodeFontSize(code);
		this._bar_code_height = this.getBarCodeHeight(code) - getBarCodeFontSize(code);
		this._bar_code_padding_top_size = this.getBarCodePaddingTopSize(code);
		this._bar_code_cell_fixed_hight = this.getBarCodeCellFixedHeight(code);
		this._text_padding_bottom_size = this.getTextPaddingBottomSize(code);
		this._text_padding_top_size = this.getTextPaddingTopSize(code);
		this._padding_bottom_size = this.getPaddingBottomByCode(code);
		this._padding_right_size = this.getPaddingRightByCode(code);
		this._bar_code_width = this.getBarCodeWidthSizeByCode(code);
	}
	
	public float get_table_width() {
		return _table_width;
	}

	public void set_table_width(float _table_width) {
		this._table_width = _table_width;
	}

	public float get_bar_code_font_size() {
		return _bar_code_font_size;
	}

	public void set_bar_code_font_size(float _bar_code_font_size) {
		this._bar_code_font_size = _bar_code_font_size;
	}

	public float get_bar_code_height() {
		return _bar_code_height;
	}

	public void set_bar_code_height(float _bar_code_height) {
		this._bar_code_height = _bar_code_height;
	}

	public float get_bar_code_padding_top_size() {
		return _bar_code_padding_top_size;
	}

	public void set_bar_code_padding_top_size(float _bar_code_padding_top_size) {
		this._bar_code_padding_top_size = _bar_code_padding_top_size;
	}

	public float get_bar_code_cell_fixed_hight() {
		return _bar_code_cell_fixed_hight;
	}

	public void set_bar_code_cell_fixed_hight(float _bar_code_cell_fixed_hight) {
		this._bar_code_cell_fixed_hight = _bar_code_cell_fixed_hight;
	}

	public float get_text_padding_bottom_size() {
		return _text_padding_bottom_size;
	}

	public void set_text_padding_bottom_size(float _text_padding_bottom_size) {
		this._text_padding_bottom_size = _text_padding_bottom_size;
	}

	public float get_text_padding_top_size() {
		return _text_padding_top_size;
	}

	public void set_text_padding_top_size(float _text_padding_top_size) {
		this._text_padding_top_size = _text_padding_top_size;
	}

	public float get_padding_bottom_size() {
		return _padding_bottom_size;
	}

	public void set_padding_bottom_size(float _padding_bottom_size) {
		this._padding_bottom_size = _padding_bottom_size;
	}

	public float get_padding_right_size() {
		return _padding_right_size;
	}

	public void set_padding_right_size(float _padding_right_size) {
		this._padding_right_size = _padding_right_size;
	}

	public float get_bar_code_width() {
		return _bar_code_width;
	}

	public void set_bar_code_width(float _bar_code_width) {
		this._bar_code_width = _bar_code_width;
	}

	/**
	 * 设置document距离A4纸的边框的距离
	 * @param code
	 * @return
	 */
	public static Document getTemplateBorder(String code)
	{
		Document document = null;
		switch (code) {
		case "1":
			document = new Document(PageSize.A4,16.2992f,16.2992f,42.9449f,42.9449f);//左、右、上、下，单位：磅
			break;
		case "2":
			document = new Document(PageSize.A4,23.5276f,23.5276f,37.7008f,37.7008f);
			break;
		case "3":
			document = new Document(PageSize.A4,0,0,0,0);
			break;
		case "4":
			document = new Document(PageSize.A4,0,0,0,0);
			break;
		case "5":
			document = new Document(PageSize.A4,22.6772f,22.6772f,24.9449f,24.9449f);
			break;
		case "6":
			document = new Document(PageSize.A4,14.1732f,14.1732f,15.5906f,15.5906f);
			break;
		case "7":
			document = new Document(PageSize.A4,34.0157f,34.0157f,24.0945f,24.0945f);
			break;
		case "8":
			document = new Document(PageSize.A8,5f,5f,60f,60f);
			break;
		default:
			document = new Document(PageSize.A4,0,0,0,0);
			break;
		}
		return document;
	}
	
	/**
	 * 设置表格宽度
	 * @param code
	 * @return  单位：磅
	 */
	public static float getMainTableWidth(String code)
	{
		float returnFloat = PageSize.A4.getWidth();
		
		switch (code) {
		case "1":
			returnFloat = PageSize.A4.getWidth() - (2 * 16.2992f);
			break;
		case "2":
			returnFloat = PageSize.A4.getWidth() - (2 * 23.5276f);
			break;
		case "5":
			returnFloat = PageSize.A4.getWidth() - (2 * 22.6772f);
			break;
		case "6":
			returnFloat = PageSize.A4.getWidth() - (2 * 14.1732f);
			break;
		case "7":
			returnFloat = PageSize.A4.getWidth() - (2 * 34.0157f);
			break;
		case "8":
			returnFloat = PageSize.A8.getWidth() - (2 * 5f);
			break;
		}
		
		return returnFloat;
	}
	
	/**
	 * 设置条码下方字体的大小
	 * @param code
	 * @return
	 */
	public static float getBarCodeFontSize(String code)
	{
		float fontSize = 10f;
		return fontSize;
	}
	
	/**
	 * 获取条码距离cell顶的高度值（调节此值，可以起到调节页面排版的效果，高度）
	 * @param code
	 * @return
	 */
	public static float getBarCodePaddingTopSize(String code)
	{
		float paddingTop = 0f;
		
		switch (code) {
		case "1":
			paddingTop = 16.4409f;//单位：磅
			break;
		case "2":
			paddingTop = 13.6063f - 0.5f;
			break;
		case "3":
			paddingTop = 17.0079f;
			break;
		case "4":
			paddingTop = 14.1732f - 1.7f;
			break;
		case "5":
			paddingTop = 11.3386f - 2f;
			break;
		case "6":
			paddingTop = 11.6220f - 1f;
			break;
		case "7":
			paddingTop = 16.8661f;
			break;
		case "8":
			paddingTop = 6f;
			break;
		}
		
		return paddingTop;
	}
	/**
	 * 获取商品名称距离cell顶部值（调节此值，可以起到调节页面排版的效果，高度）
	 * @param code
	 * @return
	 */
	public static float getTextPaddingTopSize(String code)
	{
		float paddingTop = 0f;
		
		switch (code) {
		case "1":
			paddingTop = 2.5f;//单位：磅
			break;
		case "2":
			paddingTop = 2.5f;
			break;
		case "3":
			paddingTop = 2.5f;
			break;
		case "4":
			paddingTop = 2.5f;
			break;
		case "5":
			paddingTop = 2.5f;
			break;
		case "6":
			paddingTop = 2.5f;
			break;
		case "7":
			paddingTop = 2.5f;
			break;
		case "8":
			paddingTop = 1f;
			break;
		}
		
		return paddingTop;
	}
	/**
	 * 获取商品名称距离cell底部值（调节此值，可以起到调节页面排版的效果，高度）
	 * @param code
	 * @return
	 */
	public static float getTextPaddingBottomSize(String code)
	{
		float paddingBottom = 0f;
		
		switch (code) {
		case "1":
			paddingBottom = 10.4882f;//单位：磅
			break;
		case "2":
			paddingBottom = 9.8646f - 1f;
			break;
		case "3":
			paddingBottom = 11.9055f - 0.5f;
			break;
		case "4":
			paddingBottom = 7.6535f - 1f;
			break;
		case "5":
			paddingBottom = 7.0866f - 0.85f;
			break;
		case "6":
			paddingBottom = 8.4189f - 1.5f;
			break;
		case "7":
			paddingBottom = 11.3386f;
			break;
		case "8":
			paddingBottom = 2.5f;
			break;
		}
		
		return paddingBottom;
	}
	
	/**
	 * 获取条码所在cell的高度（调节此值，可以起到调节页面排版的效果，高度）
	 * @param code
	 * @return
	 */
	public static float getBarCodeCellFixedHeight(String code)
	{
		float hightSize = 0f;
		
		switch (code) {
		case "1":
			hightSize = 80.5039f - 9f;//单位：磅
			break;
		case "2":
			hightSize = 70.8661f - 10f;
			break;
		case "3":
			hightSize = 77.6693f - 9.5f;
			break;
		case "4":
			hightSize = 62.9291f - 11.2f;
			break;
		case "5":
			hightSize = 51.5906f - 11.5f;
			break;
		case "6":
			hightSize = 62.9291f - 10.5f;
			break;
		case "7":
			hightSize = 89.2913f - 12.99f;
			break;
		case "8":
			hightSize = 77.6693f - 17.5f;
			break;
		}
		
		return hightSize;
	}
	
	/**
	 * 获取生成条码的高度
	 * @return
	 */
	public static float getBarCodeHeight(String code)
	{
		float barCodeHeight = 0;
		
		switch (code) {
		case "1":
			barCodeHeight = 64.0630f;//单位：磅
			break;
		case "2":
			barCodeHeight = 57.2598f;
			break;
		case "3":
			barCodeHeight = 60.6614f;
			break;
		case "4":
			barCodeHeight = 48.7559f;
			break;
		case "5":
			barCodeHeight = 40.2520f;
			break;
		case "6":
			barCodeHeight = 51.3071f;
			break;
		case "7":
			barCodeHeight = 68.5984f;
			break;
		case "8":
			barCodeHeight = 60f;
			break;
		}
		
		return barCodeHeight;
	}
	
	/**
	 * 设置下边距     (模板要求每个条码纸之间（上下）有间隙)
	 * @param code
	 * @return
	 */
	public static float getPaddingBottomByCode(String code)
	{
		float paddingBottomSize = 0f;
		
		switch (code) {
		case "6":
			paddingBottomSize = 5.6693f;
			break;
		}
		
		return paddingBottomSize;
	}
	
	/**
	 * 设置右边距      (模板要求每个条码纸之间（左右）有间隙)
	 * @param code
	 * @return
	 */
	public static float getPaddingRightByCode(String code)
	{
		float paddingRightSize = 0f;
		
		switch (code) {
		case "1":
			paddingRightSize = 11.3386f;//单位：磅
			break;
		case "7":
			paddingRightSize = 8.5039f;
			break;
		}
		
		return paddingRightSize;
	}
	
	/**
	 * 获取生成条码的宽度
	 * @param code
	 * @return
	 */
	public static float getBarCodeWidthSizeByCode(String code)
	{
		float barCodeWidth = 0;
		
		switch (code) {
		case "1":
			barCodeWidth = 156.1890f - 10f;//单位：磅
			break;
		case "2":
			barCodeWidth = 156.7559f;
			break;
		case "3":
			barCodeWidth = 175.1811f;
			break;
		case "4":
			barCodeWidth = 124.1008f;
			break;
		case "5":
			barCodeWidth = 108.0000f;
			break;
		case "6":
			barCodeWidth = 124.1575f;
			break;
		case "7":
			barCodeWidth = 140.5984f;
			break;
		case "8":
			barCodeWidth = 130f;
			break;
		}
		
		return barCodeWidth;
	}
	
	/**
	 * 对应条码模板，如果货品名称太长，截取长度
	 * @param code
	 * @return
	 */
	public static String getTitleByCode(String code,String title)
	{
		String return_title = title;
		
		switch (code) {
		case "1":
			if(StringLengthUtil.length(title) > 39)
				return_title = title.substring(0, StringLengthUtil.interceptSize(title, 36)) + "...";
			break;
		case "2":
			if(StringLengthUtil.length(title) > 43)
				return_title = title.substring(0, StringLengthUtil.interceptSize(title, 40)) + "...";
			break;
		case "3":
			if(StringLengthUtil.length(title) > 47)
				return_title = title.substring(0, StringLengthUtil.interceptSize(title, 44)) + "...";
			break;
		case "4":
			if(StringLengthUtil.length(title) > 33)
				return_title = title.substring(0, StringLengthUtil.interceptSize(title, 31)) + "...";
			break;
		case "5":
			if(StringLengthUtil.length(title) > 29)
				return_title = title.substring(0, StringLengthUtil.interceptSize(title, 26)) + "...";
			break;
		case "6":
			if(StringLengthUtil.length(title) > 33)
				return_title = title.substring(0, StringLengthUtil.interceptSize(title, 31)) + "...";
			break;
		case "7":
			if(StringLengthUtil.length(title) > 38)
				return_title = title.substring(0, StringLengthUtil.interceptSize(title, 35)) + "...";
			break;
		case "8":
			if(StringLengthUtil.length(title) > 47)
				return_title = title.substring(0, StringLengthUtil.interceptSize(title, 44)) + "...";
			break;
		}
		
		return return_title;
	}
	
}
